#include <iostream>

struct SumIndex {
    int i;
    int j;
    SumIndex(int ii, int jj) {
        i = ii;
        j = jj;
    }
};

SumIndex SumEqual(int arr[], int lo, int hi, int sum)
{
    for (int i = lo, j = hi; i < j;) {
        if (sum == arr[i] + arr[j]) {
            return SumIndex(i, j);
        } else if (arr[i] + arr[j] > sum) {
            --j;
        } else {
            ++i;
        }
    }

    return SumIndex(-1, -1);
}

int main(int argc, const char *argv[])
{
    int arr[] = {1, 2, 4, 7, 11, 15};
    SumIndex tmp = SumEqual(arr, 0, sizeof(arr) / sizeof(arr[0]) - 1, 15);
    std::cout << "the arr[" << tmp.i << "](" << arr[tmp.i] << ")+arr[" << tmp.j << "](" << arr[tmp.j] << ") = " << 15 << std::endl;
    return 0;
}
